/*
 * 角色
 *
 */
import _ from 'lodash';
import { defineStore } from 'pinia';
import { rzApplyApi } from '/@/api/system/rzApply';
import { nation } from '/@/config/nation.js';

export const useRzApplyStore = defineStore({
  id: 'rzApply',
  state: () => ({
    mode: '', //edit  new
    role: '',//lessee   guarantor
    bussNo: '',
    bussInfo: null, //当前查看的卡片 详情
    lesseeInfo: null, //当前编辑的承租人信息
    guarantorInfo: null, //当前编辑的保证人信息
    leaseHoldInfo: null, //当前编辑的设备信息
    custMarriage: [], //婚姻状况
    hasChildren: [], //是否有子女
    custEducation: [], //教育程度
    nationData:nation,//民族
    viewDeviceInfo:null,//当前查看的设备信息
    calcTrialParam:null,//计算参数
  }),
  getters: {
    getNationData(state) {
      return state.nationData;
    },
    getCustMarriage(state) {
      return state.custMarriage;
    },
    getHasChildren(state) { 
      return state.hasChildren;
    },
    getCustEducation(state) {
      return state.custEducation;
    },
    getBussInfo(state) {
      return state.bussInfo;
    },
    getMode(state) {
      return state.mode;
    },
    getRole(state) {
      return state.role;
    },
    getBussNo(state) {
      return state.bussNo;
    },
    getleaseHold(state) {
      return state.leaseHoldInfo;
    },
    getLessee(state) {
      return state.lesseeInfo;
    },
    getGuarantor(state) {
      return state.guarantorInfo;
    },
    getViewDeviceInfo(state){
      return state.viewDeviceInfo;
    },
    getViewLesseeInfo(state){
      return state.lesseeInfo;
    },
    getViewGuarantorInfo(state){
      return state.guarantorInfo;
    },
    getCalcTrialParam(state){
      return state.calcTrialParam
    }
  },
  actions: {
    apiCustMarriage() {
      rzApplyApi.dictByKeyCode('custMarriage').then((res) => {
        if (res.code == 0) {
          this.custMarriage = res.data;
        }
      });
    },
    apiHasChildren() {
      rzApplyApi.dictByKeyCode('hasChildren').then((res) => {
        if (res.code == 0) {
          this.hasChildren = res.data;
        }
      });
    },
    apiCustEducation() {
      rzApplyApi.dictByKeyCode('custEducation').then((res) => {
        if (res.code == 0) {
          this.custEducation = res.data;
        }
      });
    },
    clear() {
      this.mode = '';
      this.role = '';
      this.bussNo = '';
      this.lesseeInfo = {};
      this.guarantorInfo = {};
      this.leaseHoldInfo = {};
      this.apiCustMarriage();
      this.apiHasChildren();
      this.apiCustEducation();
    },

    setBussInfo(data) {
      this.bussInfo = data;
      console.log(this.bussInfo, 'this.bussInfo');
    },
    setMode(data) {
      this.mode = data;
      console.log(this.mode, 'this.mode');
    },
    setRole(data) {
      this.role = data;
      console.log(this.role, 'this.role');
    },
    setBussNo(data) {
      this.bussNo = data;
      console.log(this.bussNo, 'this.bussNo');
    },
    setleaseHold(data) {
      this.leaseHoldInfo = data;
      console.log(this.leaseHoldInfo, 'this.leaseHoldInfo');
    },
    setLessee(data) {
      this.lesseeInfo = data;
      console.log(this.lesseeInfo, 'this.lesseeInfo');
    },
    setGuarantor(data) {
      this.guarantorInfo = data;
      console.log(this.guarantorInfo, 'this.guarantorInfo');

    },
    setViewDeviceInfo(data) {
      this.viewDeviceInfo = data;
      console.log(this.viewDeviceInfo, 'this.viewDeviceInfo');
    },
    setViewLesseeInfo(data){
      this.lesseeInfo = data;
      console.log(this.lesseeInfo, 'this.lesseeInfo');
    },
    setViewSetGuarantorInfo(data){
      this.guarantorInfo = data;
      console.log(this.guarantorInfo, 'this.guarantorInfo');
    },
    setCalcTrialParam(data){
      this.calcTrialParam = data;
      console.log(this.calcTrialParam, 'this.calcTrialParam');
    }
  },
  persist: true, // 启用持久化
});
